{% extends "main.html" %}
{% block head %}
    <style>
        #login{
            height:300px;
        }
    </style>
{% endblock %}
{% block body %}
    <div id="login">
        <div class="login-row">
            <h2>重置密码</h2>
        </div>
        <input type="hidden" id="token" value="{{ token }}">
        <div class="login-row">
            <input class="form-control" type="text" name="email" id="email" readonly value="{{ email }}">
        </div>
        <div class="login-row">
            <input class="form-control" type="password" name="password" id="password" placeholder="密码">
        </div>
        <div class="login-row">
            <input class="form-control" type="password" name="repassword" id="repassword" placeholder="确认密码">
        </div>
        <div class="login-row">
            <button id="reset_password" class="btn btn-success btn-block" type="button">重置密码</button>
        </div>
    </div>

{% endblock %}

{% block script %}
    <script>
        $('#reset_password').click(function () {
            var password = $("#password").val()
            var repassword = $("#repassword").val()
            var token = $('#token').val()

            if (password.length < 6) {
                toast("密码长度过短，要大于6位")
                return false
            }
            if (password != repassword) {
                toast("密码不匹配")
                return false
            }
                $.ajax({
                    url: "{{ url_for('.do_reset_password') }}",
                    type: "put",
                    data: {'token': token, 'password': password, 'repassword': repassword},
                    success: function (result) {
                        toast('重置成功', 'success')
                        setTimeout('relocation("/")', 1000)
                    },
                    error: function (result) {
                        toast(result.responseText)
                    }
                })
        })
    </script>
{% endblock %}
